package com.aijk.ehm.sys.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.sys.mapper.extra.SysLogExtMapper;
import com.aijk.ehm.sys.model.SysLogExample;
import com.aijk.ehm.sys.model.qo.LogQo;
import com.aijk.ehm.sys.model.SysLog;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service()
public class SysLogService {

  //  private static Logger logger = LoggerFactory.getLogger(SysLogService.class);

    @Autowired
    private SysLogExtMapper sysLogMapper;


    private SysLogExample getExample(LogQo logQo) {
        SysLogExample example = new SysLogExample();
        SysLogExample.Criteria criteria = example.createCriteria();

        if (logQo != null ) {
            if (Utils.isNotEmpty(logQo.getSortway())) example.setOrderByClause(Utils.toString(logQo.getSortway()));
            if (Utils.isNotEmpty(logQo.getLogNumber())) criteria.andLogNumberEqualTo(Utils.toLong(logQo.getLogNumber()));
            if (Utils.isNotEmpty(logQo.getLogAcount())) criteria.andLogAcountEqualTo(Utils.toString(logQo.getLogAcount()));
            if (Utils.isNotEmpty(logQo.getLogModule())) criteria.andLogModuleEqualTo(Utils.toString(logQo.getLogModule()));
            if (Utils.isNotEmpty(logQo.getLogOperate())) criteria.andLogOperateEqualTo(Utils.toString(logQo.getLogOperate()));
        }

        return example;
    }

    public Integer count(LogQo logQo) {
        return sysLogMapper.countByExample(getExample(logQo));
    }

    public List<SysLog> find(LogQo logQo) {
        return sysLogMapper.selectByExample(getExample(logQo));
    }

    public PageInfo<SysLog> pageList(PagingRequest pagingRequest, LogQo logQo) {
        PageHelper.startPage(pagingRequest.getPageNum(), pagingRequest.getPageSize());
        return new PageInfo<SysLog>(sysLogMapper.selectByExample(getExample(logQo)));
    }
    public SysLog findOne(Long id) {
        return sysLogMapper.selectByPrimaryKey(id);
    }

    public Integer update(SysLog record) {
        return sysLogMapper.updateByPrimaryKeySelective(record);
    }
    public Integer save(SysLog record) {
        return sysLogMapper.insert(record);
    }

    public int saveGeneratedKeys(SysLog record) {
        return sysLogMapper.insertGeneratedKeys(record);
    }
    public Integer delete(Long id) {
        return sysLogMapper.deleteByPrimaryKey(id);
    }



}
